/**
 * 
 */
package cas.test;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author Cre.Gu
 *
 */
public class Md5Authen extends SoaAuthenticationHandlerTest {

	String dn = "uid=gcb@ZJTZSWXXJSYXGS,ou=account,bid=OR0009,bid=RE0002,bid=RE0001,bid=RE0000,dc=soa,dc=com";

	@Override
	public void testAuthenticate() throws Exception {
		super.testAuthenticate();
	}

	@Override
	public String getPassword() {
		return getPassword(password);
	}
	
	public String getPassword(String password) {
		try {
			MessageDigest digest = MessageDigest.getInstance("MD5");
			digest.update(password.getBytes());
			byte[] en = digest.digest();

			return byte2hex(en);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}

		return super.getPassword();
	}

	public String byte2hex(byte[] b) // 二行制转字符串
	{
		String hs = "";
		String stmp = "";

		for (int n = 0; n < b.length; n++) {
			stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));

			if (stmp.length() == 1)
				hs += "0" + stmp;
			else
				hs += stmp;
		}
		return hs.toUpperCase();
	}
	
	public static void main(String[] args) {
		Md5Authen m=new Md5Authen();
		System.out.println(m.getPassword("123456"));
	}

}
